<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">档案查询</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="auto" :inline="true" size="mini">
                    
                    <el-form-item label="区属:">
                        <el-select v-model="form.qs" placeholder="请选择区属名称" clearable @change="onSearch">
                            <el-option v-for="item in qslist" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="档案编号:">
                        <el-input v-model="form.dabh" placeholder="请输入档案编号" clearable @change="onSearch"></el-input>
                    </el-form-item>
                    <el-form-item label="房屋地址:">
                        <el-input v-model="form.fwdz" placeholder="请输入房屋地址" clearable @change="onSearch"></el-input>
                    </el-form-item>
                    <el-form-item label="归档类型:">
                        <el-select v-model="form.gdlx" placeholder="请选择归档类型" @change="onSearch" clearable>
                            <el-option v-for="item in gdlxlist" :key="item.code" :label="item.name" :value="item.code">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="文件类型:">
                        <el-cascader :options="yjlxlist" :props="{ checkStrictly: true }" placeholder="请选择文件类型"
                            clearable @change="handleChange" :show-all-levels="false"></el-cascader>
                    </el-form-item>
                    <el-form-item label="文件名称:">
                        <el-input v-model="form.wjmc" placeholder="请输入文件名称" clearable @change="onSearch"></el-input>
                    </el-form-item>
                    <el-form-item label="备注:">
                        <el-select v-model="form.bz" placeholder="请选择备注" clearable filterable @change="onSearch1">
                            <el-option v-for="(item, index) in cqzlbzlist" :key="index" :label="item" :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search"
                            class="searchcolor">查询</el-button>
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <!-- max-height="330" -->
            <el-table :data="tableData" style="width: 100%" :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor" :row-class-name="tableRowClassName" :cell-style="tablecellColor" border
                :max-height="maxHeight">
                <el-table-column label="区属" align="center" prop="qs" fixed></el-table-column>
                <el-table-column label="档案编号" align="center" prop="dabh"></el-table-column>
                <el-table-column label="房屋地址" align="center" prop="fwdz"
                    :show-overflow-tooltip="true" width="200"></el-table-column>
                <el-table-column label="文件类型" align="center" prop="wjlx" width="160"></el-table-column>
                <el-table-column label="文件名称" align="center" prop="wjmc" width="240" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="wjmc" label="文件预览" align="center" width="240" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <router-link target="_blank"
                            :to="{ path: '/perviewfile', query: { id: scope.row.fj[0].id, type: scope.row.fj[0].suffix } }"
                            style="color: #008A94;"
                            v-if="scope.row.fj[0].suffix == '.docx' || scope.row.fj[0].suffix == '.doc' || scope.row.fj[0].suffix == '.xls' || scope.row.fj[0].suffix == '.xlsx'">{{
                    scope.row.wjmc }}<i class="el-icon-document el-icon--right"></i>
                        </router-link>
                        <el-button type="text" size="small"
                            @click="redownload(scope.row.fj[0].id, scope.row.fj[0].name, scope.row.fj[0].suffix)"
                            v-else>{{
                    scope.row.wjmc }}<i class="el-icon-document el-icon--right"></i></el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="wjmc" label="文件下载" align="center"  width="240" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <el-button type="text" size="small"
                            @click="downloadfile(scope.row.fj[0].id, scope.row.fj[0].name, scope.row.fj[0].suffix)"
                            style="color: blue;text-decoration: underline">{{ scope.row.wjmc }}</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="bz" label="备注" align="center" :show-overflow-tooltip="true" width="240"> </el-table-column>
                <el-table-column prop="cjsj" label="上传时间" align="center" width="140">
                    <template slot-scope="scope">
                        {{ scope.row.cjsj ? scope.row.cjsj.split(' ')[0] : '' }}
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination background layout="total,prev, pager, next,jumper" :total="total"
                    :current-page.sync="current" :page-size="pageSize" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
import { dawjlist, wjbzlist,download,redownload } from '@/api/index';
import valueList from '@/components/common/valueList.vue'
import fileType from "../vo/filetype";
export default {
    name: 'swcxlist',
    data() {
        return {
            ssswlist: valueList.ssswlist,//所属事物列表
            yjlxlist: valueList.yjlxlist,//文件类型列表
            qslist: valueList.qslist,
            gdlxlist: valueList.gdlxlist,
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                wjmc: '',
                bz: '',
                buildid: '',
                gdlx: '',// 文件类型 1：产权类 2：经营类 ,
                pageSize: 10,
                current: 1
            },
            tableData: [],
            ztlist: [{ name: '是', code: 1 }, { name: '否', code: 0 }],
            maxHeight: null,
            cqzlbzlist: [],//产权资料
            //产权资料备注form
            cqzlbzform: {
                buildid: '',
                gdlx: '1',// 文件类型 1：产权类 2：经营类 ,
                pageSize: 10,
                current: 1
            },
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;'
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black'
        },
        tablecellColor() {
            return "font-weight:700;color:#000000;border-color:#c0c0c0";
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row' //这是类名
            } else {
                return ''
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.cqdawjlist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.cqdawjlist(this.form);
            this.cqwjbzlist(this.form)
            console.log('搜索');
        },
        onSearch1() {
            this.current = 1;
            this.form.current = 1;
            this.cqdawjlist(this.form);
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.form = {
                wjmc: '',
                bz: '',
                buildid: '',
                gdlx: '',// 文件类型 1：产权类 2：经营类 ,
                pageSize: 10,
                current: 1
            };
            this.cqdawjlist(this.form);
            this.cqwjbzlist(this.form)
            console.log('搜索');
        },
        // 项目列表
        cqdawjlist(data) {
            dawjlist(data).then((res) => {
                if (res.code == 200) {
                    // this.cqzlbzlist = res.data.records
                    this.tableData = res.data.records
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 产权资料文件备注
        cqwjbzlist(data) {
            wjbzlist(data).then(res => {
                console.log('备注', res)
                this.cqzlbzlist = res.data
            })
        },
        // 获取文件类型处理
        handleChange(value) {
            if (value) {
                console.log(value)
                this.form.wjlx = value[value.length - 1]
                console.log(this.form)
                this.current = 1;
                this.form.current = 1;
                this.cqdawjlist(this.form);
                this.cqwjbzlist(this.form)
            }
        },
          // 下载文件
          downloadfile(id, name, type) {
            console.log(id)
            let filetype = fileType[type];
            let data = {
                fileid: id
            }
            download(data).then(res => {
                const link = document.createElement('a');
                let blob = new Blob([res], {
                    type: filetype
                });
                link.style.display = 'none';
                //设置连接
                link.href = URL.createObjectURL(blob);
                link.download = name;
                document.body.appendChild(link);
                //模拟点击事件
                link.click();
                console.log(res)
            })
        },
        // 文件预览
        redownload(id, name, type) {
            let filetype = fileType[type];
            let data = {
                fileid: id
            }
            redownload(data).then(res => {
                console.log(res)
                let blob = new Blob([res], {
                    type: filetype
                });
                let url = window.URL.createObjectURL(blob);
                window.open(url, '_blank')
            })
        },
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 360
        })
        console.log(this.$store.getters)
        this.cqdawjlist(this.form);
        this.cqwjbzlist(this.form)
        console.log(valueList)
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}

.unloadTitle {
    text-align: left;
    padding-bottom: 10px;
    box-sizing: border-box;
    color: #606266;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
